<template>
  <div>
    <el-row>
      <el-button type="primary" style="margin-bottom: 12px" @click="handleAdd"
        >添加</el-button
      >
      <el-table
        :data="tableData"
        class="table-body"
        :header-cell-style="{ background: '#F4F6F9', color: '#1D2129' }"
        :tree-props="{ children: 'childList' }"
        row-key="moduleId"
      >
        <el-table-column prop="moduleName" label="名称"></el-table-column>
        <el-table-column prop="showFlag" label="是否显示" width="220">
          <template slot-scope="scope">
            {{ scope.row.showFlag ? "显示" : "隐藏" }}
          </template>
        </el-table-column>
        <el-table-column
          prop="createDate"
          label="创建时间"
          width="220"
        ></el-table-column>
        <el-table-column label="操作" width="180" fixed="right">
          <template slot-scope="scope">
            <el-button type="text" @click="handleCheck(scope.row.moduleId)"
              >编辑</el-button
            >
            <el-button type="text" @click="handleDelete(scope.row.moduleId)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-row>
    <Add
      ref="add"
      :tableData="tableData"
      @getParentTableData="getParentTableData"
    />
    <Detail
      ref="detail"
      :tableData="tableData"
      @getParentTableData="getParentTableData"
    />
  </div>
</template>

<script>
import { mapMutations } from "vuex";
import Add from "./Add.vue";
import Detail from "./Detail.vue";
import { deleteNavbarApi } from "@/api/modules/websites/navbar.api";

export default {
  components: { Add, Detail },
  props: ["tableData"],
  data() {
    return {
      labelPosition: "right",
      visible: false,
      id: "",
      from: {
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  // async mounted() {
  //   const item = await getUserListApi({pageNum: 1,pageSize: 10})
  //   this.tableData = item.records
  //   this.count = item.total
  // },
  methods: {
    ...mapMutations("base", ["setBreadcrumb"]),
    handleCheck(id) {
      // console.log("row", id);
      // this.id = id
      this.$refs.detail.init(id);
      // this.$router.push({ path: '/user/info' })
      // this.setBreadcrumb([{
      //   name: '人员',
      //   path: '/user'
      // }, {
      //   name: '人员详情',
      //   path: '/user/info'
      // }])
    },
    handleAdd(id) {
      this.$refs.add.init(id);
    },
    getParentTableData() {
      this.$emit("getTableData");
    },
    async handleDelete(id) {
      await deleteNavbarApi({ id });
      this.$message({
        message: "成功",
        type: "success",
      });
      this.$emit("getTableData", this.page);
    },
  },
};
</script>
